package no.sachmuld.methodcombination.examples.behaviourchain.resource;

import no.sachmuld.methodcombination.api.BehaviourChain;

/**
 *
 */
public abstract class Resource  implements AutoCloseable {

    private BehaviourChain<ResourceBehaviour> chain = new BehaviourChain<>();

    @Override
    final public void close() {
        for (ResourceBehaviour resourceBehaviour : chain.bottomUp()) {
            resourceBehaviour.close();
        }
    }

    final protected Resource with(ResourceBehaviour... resourceBehaviours) {
        chain.addAll(resourceBehaviours);
        return this;
    }



}
